<html>
<body>

<form method= "GET"  action="calculator.php">

Expression: <input type="text" name="expressions"/>
<input type = "submit" value="calculate" />
</form>
<?php

	$eq = $_GET["expressions"];
	echo $eq. "\n";
	echo '=';
 //  $num = ((-)?(\d)+ ((.)(\d)+)?);
 //	$zeroexp = ((-)?(0)+  ((.)(0)+)?);
 //	$zerocheck = (((/)((-)?(0)+  ((.)(0)+)?)$) | (/)((-)?(0)+  ((.)(0)+)?)((+)|(-)|(*)|(/));
// 	$regexp = (^((-)?(\d)+ ((.)(\d)+)?)([(\+)(\-)(\*)(\/)]((-)?(\d)+ ((.)(\d)+)?))*)$;
 	if(preg_match('((/)((-)?(0)+((.)(0)+)?)$)', $eq))
 	{
 		echo 'invalid';
 	}
 	else if(preg_match('((/)((-)?(0)+((.)(0)+)?(\+)))', $eq))
 	{
 		echo 'invalid';
 	}
 	else if(preg_match('((/)((-)?(0)+((.)(0)+)?(\-)))', $eq))
 	{
 		echo 'invalid';
 	}
 	else if(preg_match('((/)((-)?(0)+((.)(0)+)?(\*)))', $eq))
 	{
 		echo 'invalid';
 	}
 	else if(preg_match('((/)((-)?(0)+((.)(0)+)?(\/)))', $eq))
 	{
 		echo 'invalid';
 	}
 	else if(preg_match('/(-)(-)/', $eq))
 	{
 		echo 'invalid';
 	}
 	else if(preg_match('/(^(-)?(\d)+((.)(\d)+)?([(\+)(\-)(\*)(\/)](-)?(\d)+((.)(\d)+)?)*)$/', $eq))
 	{
 		 eval("\$eq = $eq;");
 		 echo $eq. "\n" ;
 	}

?>


</body>
</html>
